<template>
  <div class="content">
    <div class="cloud-header">
      <h2>门店管理</h2>
    </div>
    <div class="cloud-body">
      <div class="cloud-subset-title">
        <div class="cloud-subset-action">
          <Button color="primary" @click="addShop">+门店管理</Button>
        </div>
        <p class="cloud-subset-tips">在开发的场景同，通常一个项目管理多个应用，如微信公众号，微信小程序，数据后台等等公用的一个数据库，此处用于区分不同应用场景<br></p>
      </div>
      <div class="cloud-rules-body">
        <Table :datas="datas" :loading="loading">
          <TableItem title="门店名称 " prop="business_name"></TableItem>
          <TableItem title="门店地址" prop="address"></TableItem>
          <TableItem title="状态" align="center">
            <template slot-scope="{data}">
              {{available_state(data.available_state)}}
            </template>
          </TableItem>
          <TableItem title="操作">
            <template slot-scope="{data}">
              <button class="h-btn h-btn-no-border" :id="data._id" action="initialize" v-popup.shopEdit="data">修改</button>
              <!--               <Poptip content="确认删除?" @confirm="delPoi(datas,data)">
                <button class="h-btn h-btn-no-border">删除</button>
              </Poptip> -->
              <button class="h-btn h-btn-no-border" :id="data._heyui_uuid" v-popup.shopPay="data">支付码</button>
              <button class="h-btn h-btn-no-border" :id="data._heyui_uuid" v-popup.shopQR="data">门店码</button>
              <button class="h-btn h-btn-no-border" :id="data._heyui_uuid" v-popup.shopCard="data">联盟码</button>
            </template>
          </TableItem>
          <div slot="empty">自定义提醒：暂时无数据</div>
        </Table>
      </div>
    </div>
  </div>
</template>
<script type="text/javascript">
export default {
  data() {
    return {
      loading: false,
      datas: []
    };
  },
  /**
   * 页面加载执行
   * @return {[type]} [description]
   */
  mounted() {
    this.initialize();
  },
  methods: {
    addShop() {
      this.$router.push('/merchant/addshop');
    },
    available_state(value) {
      switch (Number(value)) {
        case 1:
          return '未生效';
        case 2:
          return '审核中';
        case 3:
          return '已生效';
        case 4:
          return '被驳回';
      }
    },
    /**
     * 删除店铺
     * @param  {[type]} id [description]
     * @return {[type]}    [description]
     */
    onDelete(datas, data) {
      this.$cloud.name('shop').where({ _id: data._id }).delete().then(res => {
        datas.splice(datas.indexOf(data), 1);
        console.log('删除数据', res);
      }).catch(error => {
        console.log('创建门店报错', error);
      });
    },
    /**
     * 删除店铺
     * @param  {[type]} id [description]
     * @return {[type]}    [description]
     */
    delPoi(datas, data) {
      this.$cloud.wechat().delPoi(data.poi_id).then(res => {
        console.log("删除返回数据", res);
        //this.onDelete(datas, data);
      }).catch(error => {
        this.$Notice.error(error.data.msg);
      });
    },
    initialize() {
      let _uniqueid = this.$cloud.userInfo()._uniqueid;
      this.loading = true;
      this.$cloud.name('shop').where({_uniqueid}).limit(-1).select().then(res => {
        this.datas = res;
        this.loading = false;
      }).catch(error => {
        this.loading = false;
        console.log('创建门店报错', error);
      });
    },
    /**
     * 下载QR二维码
     * @return {[type]} [description]
     */
    downloadQR() {
      console.log('下载支付码');
    }
  }
};

</script>
<style lang="less" scoped="true">
.cloud-rules-body {
  margin: 0 15px;
}

</style>
